package com.platform.server.controller;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.platform.server.dao.UpgradeDao;
import com.platform.server.dao.WithdrawDao;

@Controller
public class UpgradeController {
	
	
	@Autowired
	private UpgradeDao upgradeDao;
	/**
	 * 升级设置
	 */
	@RequestMapping("/upgrade")
	public Object upgrade(HttpServletRequest request,String startTime,String endTime){
		SimpleDateFormat fdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> map= new HashMap<String, Object>();
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		List<Map<String, Object>> lists = upgradeDao.selectUpgradeList(map);
		for(int i = 0;i < lists.size();i++){
			lists.get(i).put("create_time",fdt.format(lists.get(i).get("create_time")));
		}
		request.setAttribute("lists", lists);
		return "/ui/level/upgradeList.jsp";
	}
	
	/**
	 * 添加话题
	 */
	@RequestMapping("/insertUpgrade")
	public void insertUpgrade(String version,String address,String describe,String is_update,HttpServletResponse response) throws Exception{
		int flag  = upgradeDao.insertUpgrade(version, address, describe,is_update);
		JSONObject json = new JSONObject();
		json.put("flag", flag);
		response.getOutputStream().write(json.toString().getBytes("utf-8"));
	}
}
